home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / hobby / ast44src.zip / CHARTS1.C < prev    next >
C/C++ Source or Header  |  1995-02-11  |  43KB  |  1,322 lines

  1. /*
  2. ** Astrolog (Version 4.40) File: charts1.c
  3. **
  4. ** IMPORTANT NOTICE: The graphics database and chart display routines
  5. ** used in this program are Copyright (C) 1991-1995 by Walter D. Pullen
  6. ** (astara@u.washington.edu). Permission is granted to freely use and
  7. ** distribute these routines provided one doesn't sell, restrict, or
  8. ** profit from them in any way. Modification is allowed provided these
  9. ** notices remain with any altered or edited versions of the program.
  10. **
  11. ** The main planetary calculation routines used in this program have
  12. ** been Copyrighted and the core of this program is basically a
  13. ** conversion to C of the routines created by James Neely as listed in
  14. ** Michael Erlewine's 'Manual of Computer Programming for Astrologers',
  15. ** available from Matrix Software. The copyright gives us permission to
  16. ** use the routines for personal use but not to sell them or profit from
  17. ** them in any way.
  18. **
  19. ** The PostScript code within the core graphics routines are programmed
  20. ** and Copyright (C) 1992-1993 by Brian D. Willoughby
  21. ** (brianw@sounds.wa.com). Conditions are identical to those above.
  22. **
  23. ** The extended accurate ephemeris databases and formulas are from the
  24. ** calculation routines in the program "Placalc" and are programmed and
  25. ** Copyright (C) 1989,1991,1993 by Astrodienst AG and Alois Treindl
  26. ** (alois@azur.ch). The use of that source code is subject to
  27. ** regulations made by Astrodienst Zurich, and the code is not in the
  28. ** public domain. This copyright notice must not be changed or removed
  29. ** by any user of this program.
  30. **
  31. ** Initial programming 8/28,30, 9/10,13,16,20,23, 10/3,6,7, 11/7,10,21/1991.
  32. ** X Window graphics initially programmed 10/23-29/1991.
  33. ** PostScript graphics initially programmed 11/29-30/1992.
  34. ** Last code change made 1/29/1995.
  35. */
  36.  
  37. #include "astrolog.h"
  38.  
  39.  
  40. /*
  41. ******************************************************************************
  42. ** Single Chart Display Routines.
  43. ******************************************************************************
  44. */
  45.  
  46. /* Print the straight listing of planet and house positions and specified */
  47. /* by the -v switch, along with the element table, etc.                   */
  48.  
  49. void ChartListing()
  50. {
  51.   ET et;
  52.   char sz[cchSzDef];
  53.   int i, j, k, fNam, fLoc;
  54.   real rT;
  55.  
  56.   CreateElemTable(&et);
  57.   fNam = *ciMain.nam > chNull; fLoc = *ciMain.loc > chNull;
  58.  
  59.   /* Print header showing time and date of the chart being displayed. */
  60.  
  61.   AnsiColor(kWhite);
  62.   sprintf(sz, "%s %s chart ", szAppName, szVersionCore); PrintSz(sz);
  63.   if (Mon == -1)
  64.     PrintSz("(No time or space)\n");
  65.   else if (us.nRel == rcComposite)
  66.     PrintSz("(Composite)\n");
  67.   else {
  68.     sprintf(sz, "for %s%s", ciMain.nam, fNam ? "\n" : ""); PrintSz(sz);
  69.     j = DayOfWeek(Mon, Day, Yea);
  70.     sprintf(sz, "%c%c%c %s %s (%cT %s GMT)", chDay3(j),
  71.       SzDate(Mon, Day, Yea, 3), SzTim(Tim), Dst != 0.0 ? 'D' : 'S',
  72.       SzZone(Zon)); PrintSz(sz);
  73.     sprintf(sz, "%c%s%s%s\n", fLoc && !fNam ? '\n' : ' ', ciMain.loc,
  74.       fLoc ? " " : "", SzLocation(Lon, Lat)); PrintSz(sz);
  75.   }
  76.  
  77. #ifdef INTERPRET
  78.   if (us.fInterpret) {          /* Print an interpretation if -I in effect. */
  79.     if (us.nRel == rcSynastry)
  80.       InterpretSynastry();      /* Print synastry interpretaion for -r -I.  */
  81.     else
  82.       InterpretLocation();      /* Do normal interpretation for just -v -I. */
  83.     return;
  84.   }
  85. #endif
  86.  
  87.   AnsiColor(kDkGray);
  88.   if (us.fSeconds)
  89.     PrintSz("Body  Location   Ret. Declin.  Rul.      House  Rul. Velocity\n");
  90.   else {
  91.     PrintSz("Body  Locat. Ret. Decl. Rul.      House  Rul. Veloc.    ");
  92.     sprintf(sz, "%s Houses.\n", szSystem[us.nHouseSystem]); PrintSz(sz);
  93.   }
  94.   if (!fNam && !fLoc)
  95.     PrintL();
  96.  
  97.   /* Ok, now print out the location of each object. */
  98.  
  99.   for (i = 1, j = 1; i <= oNorm; i++, j++) {
  100.     if (us.fSeconds) {
  101.       if (ignore[i])
  102.         continue;
  103.     } else {
  104.       if (i > oCore && (i <= cuspHi || ignore[i]))
  105.         continue;
  106.       while (i <= oCore && j <= oCore && ignore[j])
  107.         j++;
  108.     }
  109.     if (i <= oCore && j > oCore)
  110.       PrintTab(' ', 51);
  111.     else {
  112.       if (i > oCore)
  113.         j = i;
  114.       AnsiColor(kObjA[j]);
  115.       sprintf(sz, "%-4.4s: ", szObjName[j]); PrintSz(sz);
  116.       PrintZodiac(planet[j]);
  117.       sprintf(sz, " %c ", ret[j] >= 0.0 ? ' ' : chRet); PrintSz(sz);
  118.       if (j <= cThing || j > cuspHi)
  119.         PrintAltitude(planetalt[j]);
  120.       else
  121.         PrintTab('_', us.fSeconds ? 10 : 7);
  122.       sprintf(sz, " (%c)", Dignify(j, SFromZ(planet[j])));
  123.       PrintSz(FCusp(j) ? "    " : sz);
  124.       k = inhouse[j];
  125.       AnsiColor(kSignA(k));
  126.       sprintf(sz, " [%2d%s house] ", k, szSuffix[k]); PrintSz(sz);
  127.       AnsiColor(kDefault);
  128.       sprintf(sz, "[%c] ", Dignify(j, k)); PrintSz(FCusp(j) ? "    " : sz);
  129.       if ((j != oMoo || us.fPlacalc) &&
  130.         (FObject(j) || ((j == oNod || j == oLil) && us.fPlacalc))) {
  131.         PrintCh((char)(ret[i] < 0.0 ? '-' : '+'));
  132.         rT = DFromR(RAbs(ret[j]));
  133.         sprintf(sz, us.fSeconds ? (rT < 10.0 ? "%9.7f" : "%9.6f") :
  134.           (rT < 10.0 ? "%5.3f" : "%5.2f"), rT); PrintSz(sz);
  135.       } else
  136.         PrintTab('_', us.fSeconds ? 10 : 6);
  137.     }
  138.     if (!us.fSeconds) {
  139.  
  140.       /* For some lines, we have to append the house cusp positions. */
  141.  
  142.       if (i <= cSign) {
  143.         PrintSz("  -  ");
  144.         AnsiColor(kSignA(i));
  145.         sprintf(sz, "House cusp %2d: ", i); PrintSz(sz);
  146.         PrintZodiac(house[i]);
  147.       }
  148.  
  149.       /* For some lines, we have to append the element table information. */
  150.  
  151.       if (i == cSign+2)
  152.         PrintSz("     Car Fix Mut TOT");
  153.       else if (i > cSign+2 && i < cSign+7) {
  154.         k = i-(cSign+2)-1;
  155.         AnsiColor(kElemA[k]);
  156.         sprintf(sz, "  %c%c%c%3d %3d %3d %3d",
  157.           szElem[k][0], szElem[k][1], szElem[k][2],
  158.           et.coElemMode[k][0], et.coElemMode[k][1], et.coElemMode[k][2],
  159.           et.coElem[k]); PrintSz(sz);
  160.         AnsiColor(kDefault);
  161.       } else if (i == cSign+7) {
  162.         sprintf(sz, "  TOT %2d %3d %3d %3d",
  163.           et.coMode[0], et.coMode[1], et.coMode[2], et.coSum); PrintSz(sz);
  164.       } else if (i == oCore)
  165.         PrintTab(' ', 23);
  166.       else if (i >= uranLo) {
  167.         sprintf(sz, "  Uranian #%d", i-uranLo+1); PrintSz(sz);
  168.       }
  169.       sz[0] = chNull;
  170.       switch (i-cSign-1) {
  171.       case 1: sprintf(sz, "   +:%2d", et.coYang);  break;
  172.       case 2: sprintf(sz, "   -:%2d", et.coYin);   break;
  173.       case 3: sprintf(sz, "   M:%2d", et.coMC);    break;
  174.       case 4: sprintf(sz, "   N:%2d", et.coIC);    break;
  175.       case 5: sprintf(sz, "   A:%2d", et.coAsc);   break;
  176.       case 6: sprintf(sz, "   D:%2d", et.coDes);   break;
  177.       case 7: sprintf(sz,    "<:%2d", et.coLearn); break;
  178.       }
  179.       PrintSz(sz);
  180.     } else {
  181.       PrintSz(" Decan: ");
  182.       is.fSeconds = fFalse;
  183.       PrintZodiac(Decan(planet[i]));
  184.       is.fSeconds = us.fSeconds;
  185.     }
  186.     PrintL();
  187.   }
  188.  
  189.   /* Do another loop to print out the stars in their specified order. */
  190.  
  191.   if (us.nStar) for (i = starLo; i <= starHi; i++) if (!ignore[i]) {
  192.     j = oNorm+starname[i-oNorm];
  193.     AnsiColor(kObjA[j]);
  194.     sprintf(sz, "%.4s: ", szObjName[j]); PrintSz(sz);
  195.     PrintZodiac(planet[j]);
  196.     PrintSz("   ");
  197.     PrintAltitude(planetalt[j]);
  198.     k = inhouse[j];
  199.     AnsiColor(kSignA(k));
  200.     sprintf(sz, "     [%2d%s house]", k, szSuffix[k]); PrintSz(sz);
  201.     AnsiColor(kDefault);
  202.     sprintf(sz, "     ______%s Star #%2d: %5.2f\n",
  203.       us.fSeconds ? "____" : " ", i-oNorm, starbright[j-oNorm]); PrintSz(sz);
  204.   }
  205. }
  206.  
  207.  
  208. /* Print out the aspect and midpoint grid for a chart, as specified with the */
  209. /* -g switch. (Each grid row takes up 4 lines of text.)                      */
  210.  
  211. void ChartGrid()
  212. {
  213.   char sz[cchSzDef];
  214.   int x, y, r, x1, y1, temp;
  215.  
  216. #ifdef INTERPRET
  217.   if (us.fInterpret) {    /* Print interpretation instead if -I in effect. */
  218.     InterpretGrid();
  219.     return;
  220.   }
  221. #endif
  222.  
  223.   for (y1 = 0, y = 1; y <= cObj; y++) if (!ignore[y])
  224.     for (r = 1; r <= 4; r++) {
  225.       for (x1 = 0, x = 1; x <= cObj; x++) if (!ignore[x]) {
  226.         if (y1 > 0 && x1 > 0 && y+r > 2)
  227.           PrintCh((char)(r > 1 ? chV : chC));
  228.         if (r > 1) {
  229.           temp = grid->n[x][y];
  230.  
  231.           /* Print aspect rows. */
  232.  
  233.           if (x < y) {
  234.             if (temp)
  235.               AnsiColor(kAspA[temp]);
  236.             if (r == 2)
  237.               PrintSz(temp ? szAspectAbbrev[temp] : "   ");
  238.             else if (!temp)
  239.               PrintSz("   ");
  240.             else {
  241.               if (r == 3) {
  242.                 if (grid->v[x][y] < 6000)
  243.                   sprintf(sz, "%c%2d", us.fAppSep ?
  244.                     (grid->v[x][y] < 0 ? 'a' : 's') :
  245.                     (grid->v[x][y] < 0 ? '-' : '+'), abs(grid->v[x][y])/60);
  246.                 else
  247.                   sprintf(sz, "%3d", abs(grid->v[x][y])/60);
  248.               } else
  249.                 sprintf(sz, "%02d'", abs(grid->v[x][y])%60);
  250.               PrintSz(sz);
  251.             }
  252.  
  253.           /* Print midpoint rows. */
  254.  
  255.           } else if (x > y) {
  256.             AnsiColor(kSignA(temp));
  257.             if (r == 2) {
  258.               temp = grid->n[x][y];
  259.               sprintf(sz, "%c%c%c", chSig3(temp));
  260.             } else if (r == 3) {
  261.               sprintf(sz, "%2d%c", grid->v[x][y]/60, chDeg0);
  262.             } else
  263.               sprintf(sz, "%02d'", grid->v[x][y]%60);
  264.             PrintSz(sz);
  265.  
  266.           /* Print the diagonal of object names. */
  267.  
  268.           } else {
  269.             AnsiColor(kReverse);
  270.             if (r == 2) {
  271.               AnsiColor(kObjA[y]);
  272.               sprintf(sz, "%c%c%c", chObj3(y));
  273.             } else {
  274.               temp = SFromZ(planet[y]);
  275.               AnsiColor(kSignA(temp));
  276.               if (r == 3)
  277.                 sprintf(sz, "%2d%c", (int)planet[y] - (temp-1)*30, chDeg0);
  278.               else
  279.                 sprintf(sz, "%c%c%c", chSig3(temp));
  280.             }
  281.             PrintSz(sz);
  282.           }
  283.           AnsiColor(kDefault);
  284.         } else
  285.           if (y1 > 0)
  286.             PrintTab(chH, 3);
  287.         x1++;
  288.       }
  289.       if (y+r > 2)
  290.         PrintL();
  291.       y1++;
  292.     }
  293. }
  294.  
  295.  
  296. /* This is a subprocedure of DisplayGrands(). Here we print out one aspect */
  297. /* configuration found by the parent procedure.                            */
  298.  
  299. void PrintGrand(ac, i1, i2, i3, i4)
  300. char ac;
  301. int i1, i2, i3, i4;
  302. {
  303.   char sz[cchSzDef];
  304.   int asp;
  305.  
  306.   switch (ac) {
  307.   case acS : asp = aCon; break;
  308.   case acGT: asp = aTri; break;
  309.   case acTS: asp = aOpp; break;
  310.   case acY : asp = aInc; break;
  311.   case acGC: asp = aSqu; break;
  312.   case acC : asp = aSex; break;
  313.   default: ;
  314.   }
  315.   AnsiColor(kAspA[asp]);
  316.   sprintf(sz, "%-11s", szAspectConfig[ac]); PrintSz(sz);
  317.   AnsiColor(kDefault);
  318.   sprintf(sz, " %s ",
  319.     ac == acS || ac == acGT || ac == acGC ? "with" : "from"); PrintSz(sz);
  320.   AnsiColor(kObjA[i1]);
  321.   sprintf(sz, "%c%c%c: ", chObj3(i1)); PrintSz(sz);
  322.   PrintZodiac(planet[i1]);
  323.   sprintf(sz, " %s ", ac == acS || ac == acGT ? "and" : "to "); PrintSz(sz);
  324.   AnsiColor(kObjA[i2]);
  325.   sprintf(sz, "%c%c%c: ", chObj3(i2)); PrintSz(sz);
  326.   PrintZodiac(planet[i2]);
  327.   sprintf(sz, " %s ", ac == acGC || ac == acC ? "to " : "and"); PrintSz(sz);
  328.   AnsiColor(kObjA[i3]);
  329.   sprintf(sz, "%c%c%c: ", chObj3(i3)); PrintSz(sz);
  330.   PrintZodiac(planet[i3]);
  331.   if (ac == acGC || ac == acC) {
  332.     PrintSz(" to ");
  333.     AnsiColor(kObjA[i4]);
  334.     sprintf(sz, "%c%c%c: ", chObj3(i4)); PrintSz(sz);
  335.     PrintZodiac(planet[i4]);
  336.   }
  337.   PrintL();
  338. }
  339.  
  340.  
  341. /* Scan the aspect grid of a chart and print out any major configurations, */
  342. /* as specified with the -g0 switch.                                       */
  343.  
  344. void DisplayGrands()
  345. {
  346.   int cac = 0, i, j, k, l;
  347.  
  348.   for (i = 1; i <= cObj; i++) if (!ignore[i])
  349.     for (j = 1; j <= cObj; j++) if (j != i && !ignore[j])
  350.       for (k = 1; k <= cObj; k++) if (k != i && k != j && !ignore[k]) {
  351.  
  352.         /* Is there a Stellium among the current three planets? */
  353.  
  354.         if (i < j && j < k && grid->n[i][j] == aCon &&
  355.             grid->n[i][k] == aCon && grid->n[j][k] == aCon) {
  356.           cac++;
  357.           PrintGrand(acS, i, j, k, l);
  358.  
  359.         /* Is there a Grand Trine? */
  360.  
  361.         } else if (i < j && j < k && grid->n[i][j] == aTri &&
  362.             grid->n[i][k] == aTri && grid->n[j][k] == aTri) {
  363.           cac++;
  364.           PrintGrand(acGT, i, j, k, l);
  365.  
  366.         /* Is there a T-Square? */
  367.  
  368.         } else if (j < k && grid->n[j][k] == aOpp &&
  369.             grid->n[Min(i, j)][Max(i, j)] == aSqu &&
  370.             grid->n[Min(i, k)][Max(i, k)] == aSqu) {
  371.           cac++;
  372.           PrintGrand(acTS, i, j, k, l);
  373.  
  374.         /* Is there a Yod? */
  375.  
  376.         } else if (j < k && grid->n[j][k] == aSex &&
  377.             grid->n[Min(i, j)][Max(i, j)] == aInc &&
  378.             grid->n[Min(i, k)][Max(i, k)] == aInc) {
  379.           cac++;
  380.           PrintGrand(acY, i, j, k, l);
  381.         }
  382.         for (l = 1; l <= cObj; l++) if (!ignore[l]) {
  383.  
  384.           /* Is there a Grand Cross among the current four planets? */
  385.  
  386.           if (i < j && i < k && i < l && j < l && grid->n[i][j] == aSqu &&
  387.               grid->n[Min(j, k)][Max(j, k)] == aSqu &&
  388.               grid->n[Min(k, l)][Max(k, l)] == aSqu &&
  389.               grid->n[i][l] == aSqu &&
  390.               MinDistance(planet[i], planet[k]) > 150.0 &&
  391.               MinDistance(planet[j], planet[l]) > 150.0) {
  392.             cac++;
  393.             PrintGrand(acGC, i, j, k, l);
  394.  
  395.           /* Is there a Cradle? */
  396.  
  397.           } else if (i < l && grid->n[Min(i, j)][Max(i, j)] == aSex &&
  398.               grid->n[Min(j, k)][Max(j, k)] == aSex &&
  399.               grid->n[Min(k, l)][Max(k, l)] == aSex &&
  400.               MinDistance(planet[i], planet[l]) > 150.0) {
  401.             cac++;
  402.             PrintGrand(acC, i, j, k, l);
  403.           }
  404.         }
  405.       }
  406.   if (!cac)
  407.     PrintSz("No major configurations in aspect grid.\n");
  408. }
  409.  
  410.  
  411. /* This is subprocedure of ChartWheel(). Here we print out the location */
  412. /* of a particular house cusp as well as what house cusp number it is.  */
  413.  
  414. void PrintHouse(i, left)
  415. int i, left;
  416. {
  417.   char sz[cchSzDef];
  418.  
  419.   if (!left)
  420.     PrintZodiac(house[i]);
  421.   AnsiColor(kSignA(i));
  422.   sprintf(sz, "<%d>", i); PrintSz(sz);
  423.   if (left)
  424.     PrintZodiac(house[i]);
  425.   else
  426.     AnsiColor(kDefault);
  427. }
  428.  
  429.  
  430. /* Another subprocedure of ChartWheel(). Print out one of the chart info */
  431. /* rows in the middle of the wheel (which may be blank) given an index.  */
  432.  
  433. void PrintWheelCenter(irow)
  434. int irow;
  435. {
  436.   char sz[cchSzDef];
  437.   int cch, nT;
  438.  
  439.   if (*ciMain.nam == chNull && irow >= 2)    /* Don't have blank lines if */
  440.     irow++;                                  /* the name and/or location  */
  441.   if (*ciMain.loc == chNull && irow >= 4)    /* strings are empty.        */
  442.     irow++;
  443.   switch (irow) {
  444.   case 1:
  445.     sprintf(sz, "%s %s chart", szAppName, szVersionCore);
  446.     break;
  447.   case 2:
  448.     sprintf(sz, "%s", ciMain.nam);
  449.     break;
  450.   case 3:
  451.     nT = DayOfWeek(Mon, Day, Yea);
  452.     sprintf(sz, "%c%c%c %s %s", chDay3(nT), SzDate(Mon, Day, Yea, 2),
  453.       SzTim(Tim));
  454.     break;
  455.   case 4:
  456.     sprintf(sz, "%s", ciMain.loc);
  457.     break;
  458.   case 5:
  459.     nT = (int)(RFract(RAbs(Zon))*100.0+rRound);
  460.     sprintf(sz, "%cT %c%02d:%02d, %s", Dst != 0.0 ? 'D' : 'S',
  461.       Zon > 0.0 ? '-' : '+', (int)RAbs(Zon), nT, SzLocation(Lon, Lat));
  462.     break;
  463.   case 6:
  464.     sprintf(sz, "%s Houses", szSystem[us.nHouseSystem]);
  465.     break;
  466.   case 7:
  467.     sprintf(sz, "Julian Day = %12.4f", JulianDayFromTime(T));
  468.     break;
  469.   default:
  470.     *sz = chNull;
  471.   }
  472.   cch = CchSz(sz);
  473.   nT = WHEELCOLS*2-1 + is.fSeconds*8;
  474.   PrintTab(' ', (nT - cch) / 2);
  475.   PrintSz(sz);
  476.   PrintTab(' ', nT-cch - (nT - cch) / 2);
  477. }
  478.  
  479.  
  480. /* Yet another subprocedure of ChartWheel(). Here we print out one line */
  481. /* in a particular house cell (which may be blank).                     */
  482.  
  483. void PrintWheelSlot(obj)
  484. int obj;
  485. {
  486.   char sz[cchSzDef];
  487.  
  488.   if (obj) {
  489.     AnsiColor(kObjA[obj]);
  490.     sprintf(sz, " %c%c%c ", chObj3(obj)); PrintSz(sz);
  491.     PrintZodiac(planet[obj]);
  492.     sprintf(sz, "%c ", ret[obj] < 0.0 ? 'r' : ' '); PrintSz(sz);
  493.     PrintTab(' ', WHEELCOLS-15);
  494.   } else                            /* This particular line is blank. */
  495.     PrintTab(' ', WHEELCOLS-1 + is.fSeconds*4);
  496. }
  497.  
  498.  
  499. /* Display all the objects in a wheel format on the screen, as specified */
  500. /* with the -w switch. The wheel is divided into the 12 houses and the   */
  501. /* planets are placed accordingly.                                       */
  502.  
  503. void ChartWheel()
  504. {
  505.   byte wheel[cSign][WHEELROWS];
  506.   int wheelcols, count = 0, i, j, k, l;
  507.  
  508.   /* If the seconds (-b0) flag is set, we'll print all planet and house    */
  509.   /* locations to the nearest zodiac second instead of just to the minute. */
  510.  
  511.   wheelcols = WHEELCOLS + is.fSeconds*4;
  512.  
  513.   for (i = 0; i < cSign; i++)
  514.     for (j = 0; j < us.nWheelRows; j++)    /* Clear out array from the */
  515.       wheel[i][j] = 0;                     /* last time we used it.    */
  516.  
  517.   /* This section of code places each object in the wheel house array. */
  518.  
  519.   for (i = 1; i <= cObj && count < us.nWheelRows*12; i++) {
  520.     if (ignore[i] || !(i < oMC || i == oCore || i > cuspHi))
  521.       continue;
  522.  
  523.     /* Try to put object in its proper house. If no room, */
  524.     /* then overflow over to the succeeding house.        */
  525.  
  526.     for (j = inhouse[i]-1; j < cSign; j = j < cSign ? (j+1)%cSign : j) {
  527.  
  528.       /* Now try to find the proper place in the house to put the object. */
  529.       /* This is in sorted order, although a check is made for 0 Aries.   */
  530.  
  531.       if (wheel[j][us.nWheelRows-1] > 0)
  532.         continue;
  533.       l = house[j+1] > house[Mod12(j+2)];
  534.       for (k = 0; wheel[j][k] > 0 && (planet[i] >= planet[wheel[j][k]] ||
  535.          (l && planet[i] < rDegHalf && planet[wheel[j][k]] > rDegHalf)) &&
  536.         !(l && planet[i] > rDegHalf && planet[wheel[j][k]] < rDegHalf); k++)
  537.         ;
  538.  
  539.       /* Actually insert object in proper place. */
  540.  
  541.       if (wheel[j][k] <= 0)
  542.         wheel[j][k] = i;
  543.       else {
  544.         for (l = us.nWheelRows-1; l > k; l--)
  545.           wheel[j][l] = wheel[j][l-1];
  546.         wheel[j][k] = i;
  547.       }
  548.       count++;
  549.       j = cSign;
  550.     }
  551.   }
  552.  
  553.   /* Now, if this is really the -w switch and not -w0, then reverse the */
  554.   /* order of objects in western houses for more intuitive reading.     */
  555.  
  556.   if (!us.fWheelReverse)
  557.     for (i = 3; i < 9; i++)
  558.       for (j = 0; j < us.nWheelRows/2; j++) {
  559.         k = us.nWheelRows-1-j;
  560.         l = wheel[i][j]; wheel[i][j] = wheel[i][k]; wheel[i][k] = l;
  561.       }
  562.  
  563.   /* Here we actually print the wheel and the objects in it. */
  564.  
  565.   PrintCh(chNW); PrintTab(chH, WHEELCOLS-8); PrintHouse(11, fTrue);
  566.   PrintTab(chH, WHEELCOLS-11); PrintHouse(10, fTrue);
  567.   PrintTab(chH, WHEELCOLS-10); PrintHouse(9, fTrue);
  568.   PrintTab(chH, wheelcols-4); PrintCh(chNE); PrintL();
  569.   for (i = 0; i < us.nWheelRows; i++) {
  570.     for (j = 10; j >= 7; j--) {
  571.       PrintCh(chV); PrintWheelSlot(wheel[j][i]);
  572.     }
  573.     PrintCh(chV); PrintL();
  574.   }
  575.   PrintHouse(12, fTrue); PrintTab(chH, WHEELCOLS-11);
  576.   PrintCh(chC); PrintTab(chH, wheelcols-1); PrintCh(chJN);
  577.   PrintTab(chH, wheelcols-1); PrintCh(chC); PrintTab(chH, WHEELCOLS-10);
  578.   PrintHouse(8, fFalse); PrintL();
  579.   for (i = 0; i < us.nWheelRows; i++) {
  580.     PrintCh(chV); PrintWheelSlot(wheel[11][i]); PrintCh(chV);
  581.     PrintWheelCenter(i);
  582.     PrintCh(chV); PrintWheelSlot(wheel[6][i]);
  583.     PrintCh(chV); PrintL();
  584.   }
  585.   PrintHouse(1, fTrue); PrintTab(chH, WHEELCOLS-10);
  586.   PrintCh(chJW); PrintWheelCenter(us.nWheelRows); PrintCh(chJE);
  587.   PrintTab(chH, WHEELCOLS-10); PrintHouse(7, fFalse); PrintL();
  588.   for (i = 0; i < us.nWheelRows; i++) {
  589.     PrintCh(chV); PrintWheelSlot(wheel[0][i]); PrintCh(chV);
  590.     PrintWheelCenter(us.nWheelRows+1 + i);
  591.     PrintCh(chV); PrintWheelSlot(wheel[5][i]);
  592.     PrintCh(chV); PrintL();
  593.   }
  594.   PrintHouse(2, fTrue); PrintTab(chH, WHEELCOLS-10);
  595.   PrintCh(chC); PrintTab(chH, wheelcols-1); PrintCh(chJS);
  596.   PrintTab(chH, wheelcols-1); PrintCh(chC);
  597.   PrintTab(chH, WHEELCOLS-10); PrintHouse(6, fFalse); PrintL();
  598.   for (i = 0; i < us.nWheelRows; i++) {
  599.     for (j = 1; j <= 4; j++) {
  600.       PrintCh(chV); PrintWheelSlot(wheel[j][i]);
  601.     }
  602.     PrintCh(chV); PrintL();
  603.   }
  604.   PrintCh(chSW); PrintTab(chH, wheelcols-4); PrintHouse(3, fFalse);
  605.   PrintTab(chH, WHEELCOLS-10); PrintHouse(4, fFalse);
  606.   PrintTab(chH, WHEELCOLS-10); PrintHouse(5, fFalse);
  607.   PrintTab(chH, WHEELCOLS-7); PrintCh(chSE); PrintL();
  608. }
  609.  
  610.  
  611. /* Display all aspects between objects in the chart, one per line, in       */
  612. /* sorted order based on the total "power" of the aspect, as specified with */
  613. /* the -a switch. The same influences used for -I charts are used here.     */
  614.  
  615. void ChartAspect()
  616. {
  617.   int ca[cAspect + 1], co[objMax];
  618.   char sz[cchSzDef];
  619.   int pcut = 30000, icut, jcut, phi, ihi, jhi, ahi, p, i, j, k, count = 0;
  620.   real ip, jp, rPowSum = 0.0;
  621.  
  622.   ClearB((lpbyte)ca, (cAspect + 1)*(int)sizeof(int));
  623.   ClearB((lpbyte)co, objMax*(int)sizeof(int));
  624.   loop {
  625.     phi = -1;
  626.  
  627.     /* Search for the next most powerful aspect in the aspect grid. */
  628.  
  629.     for (i = 2; i <= cObj; i++) if (!ignore[i])
  630.       for (j = 1; j < i; j++) if (!ignore[j])
  631.         if (k = grid->n[j][i]) {
  632.           ip = i <= oNorm ? objectinf[i] : 2.5;
  633.           jp = j <= oNorm ? objectinf[j] : 2.5;
  634.           p = (int)(aspectinf[k]*(ip+jp)/2.0*
  635.             (1.0-RAbs((real)(grid->v[j][i]))/60.0/aspectorb[k])*1000.0);
  636.           if ((p < pcut || (p == pcut && (i > icut ||
  637.             (i == icut && j > jcut)))) && p > phi) {
  638.             ihi = i; jhi = j; phi = p; ahi = k;
  639.           }
  640.         }
  641.     if (phi < 0)    /* Exit when no less powerful aspect found. */
  642.       break;
  643.     pcut = phi; icut = ihi; jcut = jhi;
  644.     count++;                               /* Display the current aspect.   */
  645. #ifdef INTERPRET
  646.     if (us.fInterpret) {                   /* Interpret it if -I in effect. */
  647.       InterpretAspect(jhi, ihi);
  648.       continue;
  649.     }
  650. #endif
  651.     rPowSum += (real)phi/1000.0;
  652.     ca[ahi]++;
  653.     co[jhi]++; co[ihi]++;
  654.     sprintf(sz, "%3d: ", count); PrintSz(sz);
  655.     PrintAspect(jhi, SFromZ(planet[jhi]), (int)RSgn(ret[jhi]), ahi,
  656.       ihi, SFromZ(planet[ihi]), (int)RSgn(ret[ihi]), 'a');
  657.     k = grid->v[jhi][ihi];
  658.     AnsiColor(k < 0 ? kWhite : kLtGray);
  659.     sprintf(sz, " - orb: %c%d%c%02d'",
  660.       us.fAppSep ? (k < 0 ? 'a' : 's') : (k < 0 ? '-' : '+'),
  661.       abs(k)/60, chDeg1, abs(k)%60); PrintSz(sz);
  662.     AnsiColor(kDkGreen);
  663.     sprintf(sz, " - power:%6.2f\n", (real)phi/1000.0); PrintSz(sz);
  664.     AnsiColor(kDefault);
  665.   }
  666.  
  667.   /* Now, if the -a0 switch is set, display summary information, the total */
  668.   /* number of aspects of each type, and the # of aspects to each object.  */
  669.  
  670.   if (!us.fAspSummary)
  671.     return;
  672.   PrintL();
  673.   AnsiColor(kDkGreen);
  674.   sprintf(sz, "Sum power:%7.2f - Average power:%6.2f\n",
  675.     rPowSum, rPowSum/(real)count); PrintSz(sz);
  676.   k = us.fParallel ? Min(us.nAsp, aOpp) : us.nAsp;
  677.   for (j = 0, i = 1; i <= k; i++) if (!ignorea(i)) {
  678.     if (!(j & 7)) {
  679.       if (j)
  680.         PrintL();
  681.     } else
  682.       PrintSz("   ");
  683.     AnsiColor(kAspA[i]);
  684.     sprintf(sz, "%s:%3d", szAspectAbbrev[i], ca[i]); PrintSz(sz);
  685.     j++;
  686.   }
  687.   PrintL();
  688.   for (j = 0, i = 1; i <= cObj; i++) if (!ignore[i]) {
  689.     if (!(j & 7)) {
  690.       if (j)
  691.         PrintL();
  692.     } else
  693.       PrintSz("   ");
  694.     AnsiColor(kObjA[i]);
  695.     sprintf(sz, "%c%c%c:%3d", chObj3(i), co[i]); PrintSz(sz);
  696.     j++;
  697.   }
  698.   PrintL();
  699. }
  700.  
  701.  
  702. /* Display locations of all midpoints between objects in the chart, */
  703. /* one per line, in sorted zodiac order from zero Aries onward, as  */
  704. /* specified with the -m switch.                                    */
  705.  
  706. void ChartMidpoint()
  707. {
  708.   int cs[cSign + 1];
  709.   char sz[cchSzDef];
  710.   int mcut = -1, icut, jcut, mlo, ilo, jlo, m, i, j, count = 0;
  711.   long lSpanSum = 0;
  712.  
  713.   ClearB((lpbyte)cs, (cSign + 1)*(int)sizeof(int));
  714.   is.fSeconds = fFalse;
  715.   loop {
  716.     mlo = 21600;
  717.  
  718.     /* Search for the next closest midpoint farther down in the zodiac. */ 
  719.  
  720.     for (i = 1; i < cObj; i++) if (!ignore[i])
  721.       for (j = i+1; j <= cObj; j++) if (!ignore[j]) {
  722.         m = (grid->n[j][i]-1)*30*60 + grid->v[j][i];
  723.         if ((m > mcut || (m == mcut && (i > icut ||
  724.           (i == icut && j > jcut)))) && m < mlo) {
  725.           ilo = i; jlo = j; mlo = m;
  726.         }
  727.       }
  728.     if (mlo >= 21600)    /* Exit when no midpoint farther in zodiac found. */
  729.       break;
  730.     mcut = mlo; icut = ilo; jcut = jlo;
  731.     count++;                               /* Display the current midpoint. */
  732. #ifdef INTERPRET
  733.     if (us.fInterpret) {                   /* Interpret it if -I in effect. */
  734.       InterpretMidpoint(ilo, jlo);
  735.       continue;
  736.     }
  737. #endif
  738.     cs[mlo/60/30+1]++;
  739.     sprintf(sz, "%4d: ", count); PrintSz(sz);
  740.     PrintZodiac((real)mlo/60.0);
  741.     PrintCh(' ');
  742.     PrintAspect(ilo, SFromZ(planet[ilo]), (int)RSgn(ret[ilo]), 0,
  743.       jlo, SFromZ(planet[jlo]), (int)RSgn(ret[jlo]), 'm');
  744.     AnsiColor(kDefault);
  745.     m = (int)(MinDistance(planet[ilo], planet[jlo])*60.0);
  746.     lSpanSum += m;
  747.     sprintf(sz, "-%4d%c%02d' degree span.\n", m/60, chDeg1, m%60);
  748.     PrintSz(sz);
  749.   }
  750.   is.fSeconds = us.fSeconds;
  751.  
  752.   /* Now, if the -m0 switch is set, display summary information as well, */
  753.   /* including the total number of midpoints in each sign.               */
  754.  
  755.   if (!us.fMidSummary)
  756.     return;
  757.   PrintL();
  758.   m = (int)(lSpanSum/count);
  759.   sprintf(sz, "Average span:%4d%c%02d'\n", m/60, chDeg1, m%60); PrintSz(sz);
  760.   for (i = 1; i <= cSign; i++) {
  761.     if (i == sLib)
  762.       PrintL();
  763.     else if (i != sAri)
  764.       PrintSz("   ");
  765.     AnsiColor(kSignA(i));
  766.     sprintf(sz, "%c%c%c:%3d", chSig3(i), cs[i]); PrintSz(sz);
  767.   }
  768.   PrintL();
  769. }
  770.  
  771.  
  772. /* Display locations of the objects on the screen with respect to the local */
  773. /* horizon, as specified with the -Z switch.                                */
  774.  
  775. void ChartHorizon()
  776. {
  777.   char sz[cchSzDef], szFormat[cchSzDef];
  778.   real lon, lat, sx, sy, vx, vy,
  779.     lonz[objMax], latz[objMax], azi[objMax], alt[objMax];
  780.   int fPrime, i, j, k, tot;
  781.  
  782.   /* Set up some initial variables. */
  783.  
  784.   fPrime = us.fPrimeVert;
  785.   lon = RFromD(Mod(Lon)); lat = RFromD(Lat);
  786.   tot = us.nStar ? cObj : oNorm;
  787.  
  788.   /* First find zenith location on Earth of each object. */
  789.  
  790.   for (i = 1; i <= tot; i++) if (!ignore[i] || i == oMC) {
  791.     lonz[i] = RFromD(Tropical(planet[i])); latz[i] = RFromD(planetalt[i]);
  792.     EclToEqu(&lonz[i], &latz[i]);
  793.   }
  794.  
  795.   /* Then, convert this to local horizon altitude and azimuth. */
  796.  
  797.   for (i = 1; i <= tot; i++) if (!ignore[i] && i != oMC) {
  798.     lonz[i] = RFromD(Mod(DFromR(lonz[oMC]-lonz[i]+lon)));
  799.     lonz[i] = RFromD(Mod(DFromR(lonz[i]-lon+rPiHalf)));
  800.     EquToLocal(&lonz[i], &latz[i], rPiHalf-lat);
  801.     azi[i] = rDegMax-DFromR(lonz[i]); alt[i] = DFromR(latz[i]);
  802.   }
  803.  
  804.   /* If the -Z0 switch flag is in effect, convert from altitude/azimuth  */
  805.   /* coordinates to prime vertical coordinates that we'll print instead. */
  806.  
  807.   if (fPrime) {
  808.     for (i = 1; i <= tot; i++) if (!ignore[i]) {
  809.       azi[i] = RFromD(azi[i]); alt[i] = RFromD(alt[i]);
  810.       CoorXform(&azi[i], &alt[i], rPiHalf);
  811.       azi[i] = DFromR(azi[i]); alt[i] = DFromR(alt[i]);
  812.     }
  813.   }
  814.  
  815.   /* Now, actually print the location of each object. */
  816.  
  817.   sprintf(szFormat, is.fSeconds ? " " : "");
  818.   sprintf(sz, "Body %s%sAltitude%s %s%sAzimuth%s%s  Azi. Vector%s    ",
  819.     szFormat, szFormat, szFormat, szFormat, szFormat, szFormat, szFormat,
  820.     szFormat); PrintSz(sz);
  821.   sprintf(sz, "%s Vector%s%s    Moon Vector\n\n",
  822.     us.objCenter ? "Sun" : "Earth", szFormat, szFormat); PrintSz(sz);
  823.   for (k = 1; k <= tot; k++) {
  824.     i = k <= oNorm ? k : oNorm+starname[k-oNorm];
  825.     if (ignore[i] || !FThing(i))
  826.       continue;
  827.     AnsiColor(kObjA[i]);
  828.     sprintf(sz, "%-4.4s: ", szObjName[i]); PrintSz(sz);
  829.     PrintAltitude(alt[i]);
  830.  
  831.     /* Determine directional vector based on azimuth. */
  832.  
  833.     sprintf(sz, " %s", SzDegree(azi[i])); PrintSz(sz);
  834.     sx = RCos(RFromD(azi[i])); sy = RSin(RFromD(azi[i]));
  835.     if (RAbs(sx) < RAbs(sy)) {
  836.       vx = RAbs(sx / sy); vy = 1.0;
  837.     } else {
  838.       vy = RAbs(sy / sx); vx = 1.0;
  839.     }
  840.     sprintf(sz, is.fSeconds ? " (%.3f%c" : " (%.2f%c", vy,
  841.       sy < 0.0 ? (fPrime ? 'u' : 's') : (fPrime ? 'd' : 'n')); PrintSz(sz);
  842.     sprintf(sz, is.fSeconds ? " %.2f%c)" : " %.2f%c)", vx,
  843.       sx > 0.0 ? 'e' : 'w'); PrintSz(sz);
  844.  
  845.     /* Determine distance vector of current object from Sun and Moon. */
  846.  
  847.     vx = azi[1]-azi[i]; vy = azi[2]-azi[i];
  848.     j = 1 + is.fSeconds;
  849.     sprintf(szFormat, " [%%%d.%df%%%d.%df] [%%%d.%df%%%d.%df]",
  850.       j+5, j, j+5, j, j+5, j, j+5, j);
  851.     sprintf(sz, szFormat,
  852.       RAbs(vx) < rDegHalf ? vx : RSgn(vx)*(rDegMax-RAbs(vx)), alt[1]-alt[i],
  853.       RAbs(vy) < rDegHalf ? vy : RSgn(vy)*(rDegMax-RAbs(vy)), alt[2]-alt[i]);
  854.     PrintSz(sz);
  855.     if (!is.fSeconds && i >= uranLo) {
  856.       if (i <= uranHi)
  857.         sprintf(sz, "  Uranian #%d", i-uranLo+1);
  858.       else
  859.         sprintf(sz, "  Star #%2d", i-starLo+1);
  860.       PrintSz(sz);
  861.     }
  862.     PrintL();
  863.   }
  864.   AnsiColor(kDefault);
  865. }
  866.  
  867.  
  868. /* Display x,y,z locations of each body (in AU) with respect to the Sun */
  869. /* (or whatever the specified center planet is), as in the -S switch.   */
  870. /* These values were already determined when calculating the planet     */
  871. /* positions themselves, so this procedure is basically just a loop.    */
  872.  
  873. void ChartOrbit()
  874. {
  875.   char sz[cchSzDef], szFormat[cchSzDef];
  876.   real x, y, z;
  877.   int i;
  878.  
  879.   sprintf(szFormat, is.fSeconds ? " " : "");
  880.   sprintf(sz, "Body%s    Angle%s%s%s%s    ",
  881.     szFormat, szFormat, szFormat, szFormat, szFormat);
  882.   PrintSz(sz);
  883.   sprintf(sz,
  884.     "%sX axis%s%s%s    %sY axis%s%s%s    %sZ axis%s%s%s    %sLength\n",
  885.     szFormat, szFormat, szFormat, szFormat, szFormat, szFormat, szFormat,
  886.     szFormat, szFormat, szFormat, szFormat, szFormat, szFormat);
  887.   PrintSz(sz);
  888.   for (i = 0; i <= oNorm; i++) {
  889.     if (ignore[i] || 
  890.       (!FThing(i) || ((i == oMoo || i == oSou) && !us.fPlacalc)))
  891.       continue;
  892.     AnsiColor(kObjA[i]);
  893.     sprintf(sz, "%c%c%c%c: ", chObj3(i),
  894.       szObjName[i][3] ? szObjName[i][3] : ' '); PrintSz(sz);
  895.     x = spacex[i]; y = spacey[i]; z = spacez[i];
  896.     sprintf(sz, is.fSeconds ? "[%11.7f] [%11.7f] [%11.7f] [%11.7f] [%11.7f]" :
  897.       "[%7.3f] [%7.3f] [%7.3f] [%7.3f] [%7.3f]",
  898.       planet[i], x, y, z, RSqr(x*x+y*y+z*z)); PrintSz(sz);
  899.     if (!is.fSeconds && i >= uranLo) {
  900.       sprintf(sz, "  Uranian #%d", i-uranLo+1); PrintSz(sz);
  901.     }
  902.     PrintL();
  903.   }
  904.   AnsiColor(kDefault);
  905. }
  906.  
  907.  
  908. /* Print the locations of the astro-graph lines on the Earth as specified */
  909. /* with the -L switch. This includes Midheaven and Nadir lines, zenith    */
  910. /* positions, and locations of Ascendant and Descendant lines.            */
  911.  
  912. void ChartAstroGraph()
  913. {
  914.   CrossInfo FAR *c;
  915.   char sz[cchSzDef];
  916.   real planet1[objMax], planet2[objMax], mc[objMax], ic[objMax],
  917.     as[objMax], ds[objMax], as1[objMax], ds1[objMax],
  918.     lo = Lon, longm, w, x, y, z, ad, oa, am, od, dm;
  919.   int cCross = 0, tot = cObj, i, j, k, l, m, n;
  920.  
  921.   if (us.fLatitudeCross)
  922.     {
  923.     if ((c = (CrossInfo FAR *)
  924.       PAllocate(sizeof(CrossInfo), fFalse, "crossing table")) == NULL)
  925.       return;
  926.     }
  927.  
  928. #ifdef MATRIX
  929.   for (i = 1; i <= cObj; i++) if (!ignore[i]) {
  930.     planet1[i] = RFromD(Tropical(planet[i]));
  931.     planet2[i] = RFromD(planetalt[i]);     /* Calculate zenith location on */
  932.     EclToEqu(&planet1[i], &planet2[i]);    /* Earth of each object.        */
  933.   }
  934.  
  935.   /* Print header. */
  936.  
  937.   PrintSz("Object :");
  938.   for (j = 0, i = 1; i <= cObj; i++)
  939.     if (!ignore[i] && FThing(i)) {
  940.       AnsiColor(kObjA[i]);
  941.       sprintf(sz, " %c%c%c", chObj3(i)); PrintSz(sz);
  942.       j++;
  943.     }
  944.   AnsiColor(kDefault);
  945.   PrintSz("\n------ :");
  946.   for (i = 1; i <= tot; i++)
  947.     if (!ignore[i] && FThing(i))
  948.       PrintSz(" ###");
  949.  
  950.   /* Print the longitude locations of the Midheaven lines. */
  951.  
  952.   PrintSz("\nMidheav: ");
  953.   if (lo < 0.0)
  954.     lo += rDegMax;
  955.   for (i = 1; i <= tot; i++)
  956.     if (!ignore[i] && FThing(i)) {
  957.     AnsiColor(kObjA[i]);
  958.     x = RFromD(MC)-planet1[i];
  959.     if (x < 0.0)
  960.       x += 2.0*rPi;
  961.     if (x > rPi)
  962.       x -= 2.0*rPi;
  963.     z = lo+DFromR(x);
  964.     if (z > rDegHalf)
  965.       z -= rDegMax;
  966.     mc[i] = z;
  967.     sprintf(sz, "%3.0f%c", RAbs(z), z < 0.0 ? 'e' : 'w'); PrintSz(sz);
  968.   }
  969.   AnsiColor(kDefault);
  970.  
  971.   /* The Nadir lines are just always 180 degrees away from the Midheaven. */
  972.  
  973.   PrintSz("\nNadir  : ");
  974.   for (i = 1; i <= tot; i++)
  975.     if (!ignore[i] && FThing(i)) {
  976.     AnsiColor(kObjA[i]);
  977.     z = mc[i] + rDegHalf;
  978.     if (z > rDegHalf)
  979.       z -= rDegMax;
  980.     ic[i] = z;
  981.     sprintf(sz, "%3.0f%c", RAbs(z), z < 0.0 ? 'e' : 'w'); PrintSz(sz);
  982.   }
  983.   AnsiColor(kDefault);
  984.  
  985.   /* Print the Zenith latitude locations. */
  986.  
  987.   PrintSz("\nZenith : ");
  988.   for (i = 1; i <= tot; i++)
  989.     if (!ignore[i] && FThing(i)) {
  990.       AnsiColor(kObjA[i]);
  991.       y = DFromR(planet2[i]);
  992.       sprintf(sz, "%3.0f%c", RAbs(y), y < 0.0 ? 's' : 'n'); PrintSz(sz);
  993.       as[i] = ds[i] = as1[i] = ds1[i] = rLarge;
  994.     }
  995.   PrintL2();
  996.  
  997.   /* Now print the locations of Ascendant and Descendant lines. Since these */
  998.   /* are curvy, we loop through the latitudes, and for each object at each  */
  999.   /* latitude, print the longitude location of the line in question.        */
  1000.  
  1001.   longm = RFromD(Mod(MC+lo));
  1002.   for (j = 80; j >= -80; j -= us.nAstroGraphStep) {
  1003.     AnsiColor(kDefault);
  1004.     sprintf(sz, "Asc@%2d%c: ", j >= 0 ? j : -j, j < 0 ? 's' : 'n');
  1005.     PrintSz(sz);
  1006.     for (i = 1; i <= tot; i++)
  1007.       if (!ignore[i] && FThing(i)) {
  1008.       AnsiColor(kObjA[i]);
  1009.       ad = RTan(planet2[i])*RTan(RFromD(j));
  1010.       if (ad*ad > 1.0) {
  1011.         PrintSz(" -- ");
  1012.         as1[i] = ds1[i] = cp2.dir[i] = rLarge;
  1013.       } else {
  1014.         ad = RAsin(ad);
  1015.         oa = planet1[i]-ad;
  1016.         if (oa < 0.0)
  1017.           oa += 2.0*rPi;
  1018.         am = oa-rPiHalf;
  1019.         if (am < 0.0)
  1020.           am += 2.0*rPi;
  1021.         z = longm-am;
  1022.         if (z < 0.0)
  1023.           z += 2.0*rPi;
  1024.         if (z > rPi)
  1025.           z -= 2.0*rPi;
  1026.         as1[i] = as[i];
  1027.         as[i] = z = DFromR(z);
  1028.         cp2.dir[i] = ad;
  1029.         sprintf(sz, "%3.0f%c", RAbs(z), z < 0.0 ? 'e' : 'w'); PrintSz(sz);
  1030.       }
  1031.     }
  1032.  
  1033.     /* Again, the Descendant position is related to the Ascendant's,  */
  1034.     /* being a mirror image, so it can be calculated somewhat easier. */
  1035.  
  1036.     AnsiColor(kDefault);
  1037.     sprintf(sz, "\nDsc@%2d%c: ", j >= 0 ? j : -j, j < 0 ? 's' : 'n');
  1038.     PrintSz(sz);
  1039.     for (i = 1; i <= tot; i++)
  1040.       if (!ignore[i] && FThing(i)) {
  1041.       AnsiColor(kObjA[i]);
  1042.       ad = cp2.dir[i];
  1043.       if (ad == rLarge)
  1044.         PrintSz(" -- ");
  1045.       else {
  1046.         od = planet1[i]+ad;
  1047.         dm = od+rPiHalf;
  1048.         z = longm-dm;
  1049.         if (z < 0.0)
  1050.           z += 2.0*rPi;
  1051.         if (z > rPi)
  1052.           z -= 2.0*rPi;
  1053.         ds1[i] = ds[i];
  1054.         ds[i] = z = DFromR(z);
  1055.         sprintf(sz, "%3.0f%c", RAbs(z), z < 0.0 ? 'e' : 'w'); PrintSz(sz);
  1056.       }
  1057.     }
  1058.     PrintL();
  1059. #endif /* MATRIX */
  1060.  
  1061.     /* Now, if the -L0 switch is in effect, then take these line positions, */
  1062.     /* which we saved in an array above as we were printing them, and       */
  1063.     /* calculate and print the latitude crossings.                          */
  1064.  
  1065.     if (us.fLatitudeCross)
  1066.       for (l = 1; l <= cObj; l++) if (!ignore[l] && FThing(l))
  1067.         for (k = 1; k <= cObj; k++) {
  1068.           if (ignore[k] || !FThing(k))
  1069.             continue;
  1070.           for (n = 0; n <= 1; n++) {
  1071.             x = n ? ds1[l] : as1[l];
  1072.             y = n ? ds[l] : as[l];
  1073.             for (m = 0; m <= 1; m++) {
  1074.  
  1075.             /* Check if Ascendant/Descendant cross Midheaven/Nadir. */
  1076.  
  1077.             z = m ? ic[k] : mc[k];
  1078.             if (cCross < MAXCROSS &&
  1079.               RAbs(x-y) < rDegHalf && RSgn(z-x) != RSgn(z-y)) {
  1080.               c->obj1[cCross] = n ? -l : l;
  1081.               c->obj2[cCross] = m ? -k : k;
  1082.               c->lat[cCross] = (real)j+5.0*RAbs(z-y)/RAbs(x-y);
  1083.               c->lon[cCross] = z;
  1084.               cCross++;
  1085.             }
  1086.  
  1087.             /* Check if Ascendant/Descendant cross another Asc/Des. */
  1088.  
  1089.             w = m ? ds1[k] : as1[k];
  1090.             z = m ? ds[k] : as[k];
  1091.             if (cCross < MAXCROSS && k > l &&
  1092.                 RAbs(x-y)+RAbs(w-z) < rDegHalf && RSgn(w-x) != RSgn(z-y)) {
  1093.               c->obj1[cCross] = n ? -l : l;
  1094.               c->obj2[cCross] = 100+(m ? -k : k);
  1095.               c->lat[cCross] = (real)j+5.0*
  1096.                 RAbs(y-z)/(RAbs(x-w)+RAbs(y-z));
  1097.               c->lon[cCross] = Min(x, y)+RAbs(x-y)*
  1098.                 RAbs(y-z)/(RAbs(x-w)+RAbs(y-z));
  1099.               cCross++;
  1100.             }
  1101.           }
  1102.         }
  1103.     }
  1104.   }
  1105.   if (!us.fLatitudeCross)
  1106.     return;
  1107.   PrintL();
  1108.  
  1109.   /* Now, print out all the latitude crossings we found.  */
  1110.   /* First, we sort them in order of decreasing latitude. */
  1111.  
  1112.   for (i = 1; i < cCross; i++) {
  1113.     j = i-1;
  1114.     while (j >= 0 && c->lat[j] < c->lat[j+1]) {
  1115.       SwapN(c->obj1[j], c->obj1[j+1]); SwapN(c->obj2[j], c->obj2[j+1]);
  1116.       SwapR(&c->lat[j], &c->lat[j+1]); SwapR(&c->lon[j], &c->lon[j+1]);
  1117.       j--;
  1118.     }
  1119.   }
  1120.   for (i = 1; i < cCross; i++) {
  1121.     j = abs(c->obj1[i]);
  1122.     AnsiColor(kObjA[j]);
  1123.     sprintf(sz, "%c%c%c ", chObj3(j)); PrintSz(sz);
  1124.     AnsiColor(kElemA[c->obj1[i] > 0 ? eFir : eAir]);
  1125.     PrintSz(c->obj1[i] > 0 ? "Ascendant " : "Descendant");
  1126.     AnsiColor(kWhite);
  1127.     PrintSz(" crosses ");
  1128.     j = abs(c->obj2[i] - (c->obj2[i] < 50 ? 0 : 100));
  1129.     AnsiColor(kObjA[j]);
  1130.     sprintf(sz, "%c%c%c ", chObj3(j)); PrintSz(sz);
  1131.     AnsiColor(kElemA[c->obj2[i] < 50 ?
  1132.       (c->obj2[i] > 0 ? eEar : eWat) : (c->obj2[i] > 100 ? eFir : eAir)]);
  1133.     sprintf(sz, "%s ", c->obj2[i] < 50 ? (c->obj2[i] > 0 ? "Midheaven " :
  1134.       "Nadir     ") : (c->obj2[i] > 100 ? "Ascendant " : "Descendant"));
  1135.     PrintSz(sz);
  1136.     AnsiColor(kDefault);
  1137.     sprintf(sz, "at %s%c,", SzDegree(c->lon[i]),
  1138.       c->lon[i] < 0.0 ? 'E' : 'W'); PrintSz(sz);
  1139.     j = (int)(RFract(RAbs(c->lat[i]))*60.0);
  1140.     sprintf(sz, "%s%c\n", SzDegree(c->lat[i]),
  1141.       c->lat[i] < 0.0 ? 'S' : 'N'); PrintSz(sz);
  1142.   }
  1143.   DeallocateFar(c);
  1144.   if (!cCross) {
  1145.     AnsiColor(kDefault);
  1146.     PrintSz("No latitude crossings.\n");
  1147.   }
  1148. }
  1149.  
  1150.  
  1151. /* Another important procedure: Display any of the types of (text) charts    */
  1152. /* that the user specified they wanted, by calling the appropriate routines. */
  1153.  
  1154. void PrintChart(fProg)
  1155. bool fProg;
  1156. {
  1157.   int fCall = fFalse;
  1158.  
  1159.   if (us.fListing) {
  1160.     if (is.fMult)
  1161.       PrintL2();
  1162.     if (us.nRel < rcDifference)
  1163.       ChartListing();
  1164.     else
  1165.  
  1166.       /* If the -rb or -rd relationship charts are in effect, then instead  */
  1167.       /* of doing the standard -v chart, print either of these chart types. */
  1168.  
  1169.       DisplayRelation();
  1170.     is.fMult = fTrue;
  1171.   }
  1172.   if (us.fWheel) {
  1173.     if (is.fMult)
  1174.       PrintL2();
  1175.     ChartWheel();
  1176.     is.fMult = fTrue;
  1177.   }
  1178.   if (us.fGrid) {
  1179.     if (is.fMult)
  1180.       PrintL2();
  1181.     if (us.nRel > rcDual) {
  1182.       fCall = us.fSmartCusp; us.fSmartCusp = fFalse;
  1183.       if (!FCreateGrid(fFalse))
  1184.         return;
  1185.       us.fSmartCusp = fCall;
  1186.       not(fCall);
  1187.       ChartGrid();
  1188.       if (us.fGridConfig) {    /* If -g0 switch in effect, then  */
  1189.         PrintL();              /* display aspect configurations. */
  1190.         if (!fCall)
  1191.           FCreateGrid(fFalse);
  1192.         DisplayGrands();
  1193.       }
  1194.     } else {
  1195.  
  1196.       /* Do a relationship aspect grid between two charts if -r0 in effect. */
  1197.  
  1198.       fCall = us.fSmartCusp; us.fSmartCusp = fFalse;
  1199.       if (!FCreateGridRelation(us.fGridConfig))
  1200.         return;
  1201.       us.fSmartCusp = fCall;
  1202.       ChartGridRelation();
  1203.     }
  1204.     is.fMult = fTrue;
  1205.   }
  1206.   if (us.fAspList) {
  1207.     if (is.fMult)
  1208.       PrintL2();
  1209.     if (us.nRel > rcDual) {
  1210.       if (!fCall) {
  1211.         fCall = fTrue;
  1212.         if (!FCreateGrid(fFalse))
  1213.           return;
  1214.       }
  1215.       ChartAspect();
  1216.     } else {
  1217.       if (!FCreateGridRelation(fFalse))
  1218.         return;
  1219.       ChartAspectRelation();
  1220.     }
  1221.     is.fMult = fTrue;
  1222.   }
  1223.   if (us.fMidpoint) {
  1224.     if (is.fMult)
  1225.       PrintL2();
  1226.     if (us.nRel > rcDual) {
  1227.       if (!fCall) {
  1228.         if (!FCreateGrid(fFalse))
  1229.           return;
  1230.       }
  1231.       ChartMidpoint();
  1232.     } else {
  1233.       if (!FCreateGridRelation(fTrue))
  1234.         return;
  1235.       ChartMidpointRelation();
  1236.     }
  1237.     is.fMult = fTrue;
  1238.   }
  1239.   if (us.fHorizon) {
  1240.     if (is.fMult)
  1241.       PrintL2();
  1242.     if (us.fHorizonSearch)
  1243.       ChartInDayHorizon();
  1244.     else
  1245.       ChartHorizon();
  1246.     is.fMult = fTrue;
  1247.   }
  1248.   if (us.fOrbit) {
  1249.     if (is.fMult)
  1250.       PrintL2();
  1251.     ChartOrbit();
  1252.     is.fMult = fTrue;
  1253.   }
  1254.   if (us.fInfluence) {
  1255.     if (is.fMult)
  1256.       PrintL2();
  1257.     ChartInfluence();
  1258.     is.fMult = fTrue;
  1259.   }
  1260.   if (us.fAstroGraph) {
  1261.     if (is.fMult)
  1262.       PrintL2();
  1263.     ChartAstroGraph();
  1264.     is.fMult = fTrue;
  1265.   }
  1266.   if (us.fCalendar) {
  1267.     if (is.fMult)
  1268.       PrintL2();
  1269.     if (us.fCalendarYear)
  1270.       ChartCalendarYear();
  1271.     else
  1272.       ChartCalendarMonth();
  1273.     is.fMult = fTrue;
  1274.   }
  1275.   if (us.fInDay) {
  1276.     if (is.fMult)
  1277.       PrintL2();
  1278.     ChartInDaySearch(fProg);
  1279.     is.fMult = fTrue;
  1280.   }
  1281.   if (us.fInDayInf) {
  1282.     if (is.fMult)
  1283.       PrintL2();
  1284.     ChartInDayInfluence();
  1285.     is.fMult = fTrue;
  1286.   }
  1287.   if (us.fEphemeris) {
  1288.     if (is.fMult)
  1289.       PrintL2();
  1290.     ChartEphemeris();
  1291.     is.fMult = fTrue;
  1292.   }
  1293.   if (us.fTransit) {
  1294.     if (is.fMult)
  1295.       PrintL2();
  1296.     ChartTransitSearch(fProg);
  1297.     is.fMult = fTrue;
  1298.   }
  1299.   if (us.fTransitInf) {
  1300.     if (is.fMult)
  1301.       PrintL2();
  1302.     ChartTransitInfluence(fProg);
  1303.     is.fMult = fTrue;
  1304.   }
  1305. #ifdef ARABIC
  1306.   if (us.nArabic) {
  1307.     if (is.fMult)
  1308.       PrintL2();
  1309.     DisplayArabic();
  1310.     is.fMult = fTrue;
  1311.   }
  1312. #endif
  1313.  
  1314.   if (!is.fMult) {          /* Assume the -v chart if user */
  1315.     us.fListing = fTrue;    /* didn't indicate anything.   */
  1316.     PrintChart(fProg);
  1317.     is.fMult = fTrue;
  1318.   }
  1319. }
  1320.  
  1321. /* charts1.c */
  1322.